package com.doit.day01;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;

public class _01_缓存 {
    public static void main(String[] args) throws Exception {
        //模拟的缓存其实是一个hashMap
        HashMap<Integer, String> map = new HashMap<>();


        HashMap<String, ArrayList<String>> map1 = new HashMap<>();
        HashMap<String, HashMap<String,String>> map2 = new HashMap<>();


        //模拟一下去mysql数据库中查找数据
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
        PreparedStatement pps = conn.prepareStatement("select name from user_info where id = ?");
        for (int i = 0; i < 100; i++) {
            //要先去缓存中漏一下，看有还是没有
            String s = map.get(i);
            if (s != null){
                //有数据   就可以正常进行处理
                System.out.println(s.toUpperCase());
            }else {
                pps.setInt(1,i);
                ResultSet resultSet = pps.executeQuery();
                while (resultSet.next()){
                    String name = resultSet.getString("name");
                    System.out.println(name);
                    //缓存里现在有数据吗？
                    map.put(i,name);
                }
            }
        }

        pps.close();
        conn.close();


    }
}
